package main.com.dhj.test02

object test03 {

    def main(args: Array[String]): Unit = {

        println("Factorial of 2: " + factorial(2))
        println("Factorial of 3: " + factorial(3))
        println("----------------------------------------")

        println("Factorial of 2 =" + func01(2));
        println("Factorial of 3 =" + func01(3));

    }


    private def factorial(x: Int): Int = {
        def fact(x: Int, acc: Int): Int = {
            if (x <= 1) acc
            else fact(x - 1, x * acc)
        }

        fact(x, 1)
    }


    def func01(x: Int): Int = {
        func02(x, 1)
    }

    def func02(x: Int, acc: Int): Int = {
        if (x <= 1) acc
        else func02(x - 1, x * acc)
    }

}

